﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;

namespace YouHP.Pages
{
    public class ListUsers : BasePage
    {
        protected List<UserInfo> mUserLst;
        protected List<AreaInfo> mProvinceLst;
        protected List<DiseaseInfo> mDiseaseLst;
        protected List<TreatmentInfo> mTreatmentLst;
        protected List<SymptomInfo> mSymptomLst;
        protected int _pageCount = 0;
        protected int _UserCount = 0;
        protected int _pageSize = 2;
        protected int _pageIndex = 1;

        protected int _firstpage = 1;
        protected int _prevpage;
        protected int _nextpage;
        protected string url = "ListUsers.aspx?";


        protected static List<string> mPingYin = new List<string>();

        static ListUsers()
        {
            for (char c = 'A'; c <= 'Z'; c++)
            {
                mPingYin.Add(c.ToString());
            }
        }

        protected override void ShowPage()
        {
            //SeoTitle = "分享";
            PageTitle = "病友列表";

            //mProvinceLst = AreaBLL.Instance.GetProvinceList();
            mDiseaseLst = DiseaseBLL.Instance.GetAllDiseaseByName("");
            mTreatmentLst = TreatmentBLL.Instance.GetAllTreatmentByName("");
            mSymptomLst = SymptomBLL.Instance.GetAllSymptomByName("");
           
            
            //当前页

            _pageIndex = RequestTools.GetQueryInt("page", 1);

            //页面跳转
            int pagesel = RequestTools.GetFormInt("pagesel", 0);
            if (pagesel != 0) _pageIndex = pagesel;
            
             mUserLst = UserList();
             if (mUserLst == null) AddErrLine("没有满足条件的病友！");

            //分页计算
            _pageCount = _UserCount / _pageSize;

            if (_UserCount / _pageSize == 0) _pageCount++;

            else if (_UserCount % _pageSize != 0) _pageCount++;

            //前后翻页计算
            _prevpage = _pageIndex - 1;
            if (_prevpage == 0) _prevpage++;

            _nextpage = _pageIndex + 1;
            if (_nextpage > _pageCount) _nextpage = _pageCount;

        }


        public List<UserInfo> UserList()
        {

           
                ////按地区搜索病人
                //int  provinceId = RequestTools.GetFormString("province");
                //int  cityId = RequestTools.GetFormString("city");
                //if ((!province.Equals("")) || (!city.Equals("")))
                //{
                //    mUserLst = UserBLL.Instance.GetUserListByArea(_pageSize, _pageIndex, provinceId, cityId, Constants.USER_PATIENT, out _UserCount);
                //    return mUserLst;
                //}


                //按年龄范围搜索
                int minAge = RequestTools.GetFormInt("minage", -1);
                int maxAge = RequestTools.GetFormInt("maxage", -1);
                
                if ((minAge != -1) || (maxAge != -1))
                {

                    //mUserLst = UserBLL.Instance.GetPatientsListByAge(_pageSize, _pageIndex, minAge, maxAge, out _UserCount);
                    return mUserLst;
                }


                //按用户名搜索
                string userName = RequestTools.GetFormString("username");
                if (!userName.Equals(""))
                {
                    mUserLst = UserBLL.Instance.GetUserListByUserName(_pageSize, _pageIndex, userName, Constants.USER_PATIENT, out _UserCount);
                    if (mUserLst.Count == 0)
                        AddErrLine("不存在这个病友！");

                    return mUserLst;
                }


                //按疾病搜索
                int  diseaseId = RequestTools.GetFormInt("disease",-1);
               
                if (diseaseId != -1)
                {
                    mUserLst = UserBLL.Instance.GetUserListByDiseaseId(_pageSize, _pageIndex, diseaseId, Constants.USER_PATIENT, out _UserCount);
                    return mUserLst;
                }

                //按治疗搜索
                int  treatmentId = RequestTools.GetFormInt("treatmentname",-1);
               
                if (treatmentId != -1)
                {
                    mUserLst = UserBLL.Instance.GetUserListByTreatmentId(_pageSize, _pageIndex, treatmentId, Constants.USER_PATIENT, out _UserCount);
                    return mUserLst;
                }

                //按症状搜索
                int  symptomId = RequestTools.GetFormInt("symptomname",-1);
               
                if (symptomId != -1)
                {
                    mUserLst = UserBLL.Instance.GetUserListBySymptomId(_pageSize, _pageIndex, symptomId, Constants.USER_PATIENT, out _UserCount);
                    return mUserLst;
                }

           

            //拼音首字母排列

            //string pinyin = RequestTools.GetQueryString("PinYin");
            //if (!pinyin.Equals(""))
            //{

            //    url = url + "PinYin=" + pinyin;
            //    mUserLst = UserBLL.Instance.GetUserByPinYin(_pageSize, _pageIndex, pinyin, out _UserCount);
            //    return mUserLst;
            //}


            else
            {
                mUserLst = UserBLL.Instance.SearchPatientsList(_pageSize, _pageIndex, out _UserCount);

                return mUserLst;

            }

        }
    }
}
